home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3121 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  61 lines

  1. Path: eagle.novo.dk!usenet
  2. From: morb@novo.dk (Morten Brun)
  3. Newsgroups: comp.lang.c++
  4. Subject: Unicode and c++ !!!
  5. Date: Mon, 22 Jan 1996 09:57:35 GMT
  6. Organization: Novo Nordisk
  7. Message-ID: <4dvmrv$bh0@eagle.novo.dk>
  8. NNTP-Posting-Host: dhcp250-178.novo.dk
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I am having a big problem when trying to convert from ascii to Unicode
  12. by using the wsprintf function. Here is a little "working" sample.
  13. Any help will be greately appreciated.
  14.  
  15. #define UNICODE 1
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>          
  19. #include <iostream.h>
  20.  
  21. int Test(LPWSTR lpwszString);
  22. int err = 0;
  23.  
  24. main()
  25. {
  26. char sAscii[255];
  27. LPWSTR    sUniCode = NULL;
  28.  
  29.     // This works
  30.     err = Test( TEXT("This is a ascii string"));
  31.  
  32.     // This does not work !!!!
  33.     strcpy(sAscii,"This is a ascii string");
  34.     
  35.     wsprintf(sUniCode,TEXT("%S"),sAscii);
  36.     
  37.     err = Test(sUniCode);
  38.  
  39. return( 0 );
  40. }
  41.  
  42. int Test(LPWSTR lpwszString)
  43. {
  44.     char sString[255];
  45.  
  46.     // Print the Unicode
  47.     cout << "Unciode: " << lpwszString << endl;
  48.  
  49.     // Convert Unicode to Ascii
  50.     sprintf (sString ,"%S",lpwszString);
  51.     cout << "Ascii :" << sString << endl;
  52.     return(0);
  53. }
  54.  
  55.  
  56.     
  57. Morten Brun
  58. Novo Nordisk IT, Denmark
  59. morb@novo.dk
  60.  
  61.